#!/bin/sh

eval `/mnt/ESensor/htdocs/proccgi.sh $*`

cd /mnt/ESensor/

#用户配置文件路径
userConfigPath="/mnt/ESensor/etc/"

#检测用户数据的旧密码是否正常
IsPwdOk=`grep -w $FORM_user_pwd $userConfigPath/.ESensor.user`


echo "Content-type: text/html"
echo ""

cat << EOF
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<style type="text/css">
		body{ color: yellow;}
	</style>
</head>
EOF

cat << EOF
<body>
EOF

CheckConfig=`curl "http://$FORM_http_host.a.diyeasy.com.cn/admin/mdh.action?UID=$FORM_user_name&PASS=$FORM_user_newpwd&WAPID=1d&DEVID=0&CMD=ReadTime"`
CheckConfig=`echo "$CheckConfig" | grep "0~0;" -o`
if [ "$CheckConfig" != "" ] ; then

cat << EOF
	<b> 营业厅信息配置成功 </b><br>
	<b>主机名:$FORM_http_host</b><br>
	<b>营业厅新编号：$FORM_user_name</b><br>
	<b>营业厅新密码：$FORM_user_newpwd</b><br>
EOF

sed "1c $FORM_user_name:$FORM_user_newpwd:$FORM_http_host:0" $userConfigPath/.ESensor.user -i

else
cat <<EOF
	<p> 不能登陆主机$FORM_http_host的$FORM_user_name营业厅，修改失败！<br>
	请核实营业厅编号、密码、主机名输入是否正确！</p>
EOF
fi

cat << EOF
</body>
</html>
EOF
